#ifndef HISTORYMSG_COMMAND_IN_H_
#define HISTORYMSG_COMMAND_IN_H_
#include "command.h"

#pragma pack(1)
namespace Cmd
{
        namespace HistoryMsg
        {
                //  cmd declaration
                enum {
                        CMDIN_LOGIN             = 0x0010,		// 登录HistoryMsgServer验证指令
                        CMDIN_DISCUSS           = 0x0011,
                        CMDIN_GROUP             = 0x0012,
                        CMDIN_SESSION           = 0x0013,
                        CMDIN_ROOM              = 0x0014,
                };
                enum { //CMDIN_LOGIN
                        SCMDIN_LOGIN                    = 0x0001,	// 请求登录HistoryMsgServer
                        SCMDIN_LOGIN_RESPONCE           = 0x0002,	// 登录HistoryMsgServer返回
                };
                enum { //CMDIN_DISCUSS
                        SCMDIN_HISTORY_MSG_SAVE         = 0x0001,
                        SCMDIN_OFFLINE_MSG_REQ          = 0x0002,
                        SCMDIN_OFFLINE_MSG_RES          = 0x0003,
                };
                enum { //CMDIN_GROUP
                        SCMDIN_GROUP_HISTORY_MSG_SAVE   = 0x0001,
                        SCMDIN_GROUP_OFFLINE_MSG_REQ    = 0x0002,
                        SCMDIN_GROUP_OFFLINE_MSG_RES    = 0x0003,
                        SCMDIN_GROUP_OFFLINE_MSG_SAVE   = 0x0004,
                };
                enum { //CMDIN_SESSION
                        SCMDIN_INDIVIDUAL_HISTORY_MSG_SAVE      = 0x0001,
                };
                enum { //CMDIN_ROOM
                        SCMDIN_ROOM_HISTORY_MSG_SAVE    = 0x0001,
                };

                //	cmd definition
                struct stLoginCmd:t_NullCmd
                {
                        stLoginCmd():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN)
                        {
                                dest_type_ = HISTORYMSGSERVER;
                                server_type_ = 0;
                                server_id_ = 0;
                        }
                        WORD dest_type_;
                        WORD server_type_;
                        DWORD server_id_;
                };
                struct stLoginResponce:t_NullCmd
                {
                        stLoginResponce():
                                t_NullCmd(CMDIN_LOGIN, SCMDIN_LOGIN_RESPONCE)
                        {
                        }
                };

                struct stHistoryMsgSave:
                        t_NullCmd
                {
                        stHistoryMsgSave():
                                t_NullCmd(CMDIN_DISCUSS, SCMDIN_HISTORY_MSG_SAVE)
                        {
                                discuss_id_ = 0;
                                user_id_ = 0;
                                msg_id_ = 0;
                                msg_size_ = 0;
                        }
                        void setDiscussID(const DWORD &did)     { discuss_id_ = did; }
                        void setUserID(const DWORD &uid)        { user_id_ = uid; }
                        void setUserName(const std::string &name)       { strncpy(user_name_, name.c_str(), MAX_ACCOUNT_SIZE);}
                        void setMsg(const DWORD &msgid, const char *msg, const WORD &len) {
                                msg_id_ = msgid;
                                msg_size_ = len;
                                bcopy(msg, msg_data_, len);
                        }

                        DWORD discuss_id_;
                        DWORD user_id_;
                        char user_name_[MAX_ACCOUNT_SIZE+1];
                        DWORD msg_id_;
                        WORD msg_size_;
                        char msg_data_[0];
                        DWORD getSize() {
                                return sizeof(*this)+msg_size_*sizeof(msg_data_[0]);
                        }
                };
                struct stOfflineMsgReq:
                        t_NullCmd
                {
                        stOfflineMsgReq():
                                t_NullCmd(CMDIN_DISCUSS, SCMDIN_OFFLINE_MSG_REQ)
                        {
                                discuss_id_ = 0;
                                user_id_ = 0;
                                num_ = 0;
                        }
                        DWORD discuss_id_;
                        DWORD user_id_;
                        WORD  num_;
                };
                struct stOfflineMsgRes:
                        t_NullCmd
                {
                        stOfflineMsgRes():
                                t_NullCmd(CMDIN_DISCUSS, SCMDIN_OFFLINE_MSG_RES)
                        {
                                discuss_id_ = 0;
                                user_id_ = 0;
                                sender_id_ = 0;
                                msg_id_ = 0;
                                msg_size_ = 0;
                        }
                        DWORD getSize() {
                                return sizeof(*this) + msg_size_*msg_data_[0];
                        }
                        DWORD discuss_id_;
                        DWORD user_id_;
                        DWORD sender_id_;
                        DWORD msg_id_;
                        WORD  msg_size_;
                        char  msg_data_[0];
                };

                struct stGroupHistoryMsgSave:
                        t_NullCmd
                {
                        stGroupHistoryMsgSave():
                                t_NullCmd(CMDIN_GROUP, SCMDIN_GROUP_HISTORY_MSG_SAVE)
                        {
                                group_id_ = 0;
                                user_id_ = 0;
                                msg_id_   = 0;
                                msg_type_ = eChatMsgType_text;
                                msg_size_ = 0;
                                bzero(user_name_, sizeof(user_name_));
                        }
                        void setGroupID(const DWORD &gid)       { group_id_ = gid; }
                        void setUserID(const DWORD &uid)        { user_id_ = uid; }
                        void setUserName(const std::string &name)       { strncpy(user_name_, name.c_str(), MAX_ACCOUNT_SIZE);}
                        void setMsg(const DWORD &msgno, const BYTE &msgtype, const char *msg, const WORD &len) {
                                msg_id_   = msgno;
                                msg_type_ = msgtype;
                                msg_size_ = len;
                                bcopy(msg, msg_data_, len);
                        }

                        DWORD group_id_;
                        DWORD user_id_;
                        char user_name_[MAX_ACCOUNT_SIZE+1];
                        DWORD msg_id_;
                        BYTE msg_type_;
                        WORD msg_size_;
                        char msg_data_[0];
                        DWORD getSize() {
                                return sizeof(*this)+msg_size_*sizeof(msg_data_[0]);
                        }
                };
                struct stGroupOfflineMsgReq:
                        t_NullCmd
                {
                        stGroupOfflineMsgReq():
                                t_NullCmd(CMDIN_GROUP, SCMDIN_GROUP_OFFLINE_MSG_REQ)
                        {
                                group_id_ = 0;
                                user_id_ = 0;
                                num_ = 0;
                        }
                        DWORD group_id_;
                        DWORD user_id_;
                        WORD  num_;
                };
                struct stGroupOfflineMsgRes:
                        t_NullCmd
                {
                        stGroupOfflineMsgRes():
                                t_NullCmd(CMDIN_GROUP, SCMDIN_GROUP_OFFLINE_MSG_RES)
                        {
                                group_id_ = 0;
                                user_id_ = 0;
                                sender_id_ = 0;
                                msg_id_   = 0;
                                msg_type_ = eChatMsgType_text;
                                msg_size_ = 0;
                        } 
                        DWORD getSize() {
                                return sizeof(*this) + msg_size_*msg_data_[0];
                        }
                        DWORD group_id_;
                        DWORD user_id_;
                        DWORD sender_id_;
                        DWORD msg_id_;
                        BYTE  msg_type_;
                        WORD  msg_size_;
                        char  msg_data_[0];
                };
                struct stGroupOfflineMsgSave:
                        t_NullCmd
                {
                        stGroupOfflineMsgSave():
                                t_NullCmd(CMDIN_GROUP, SCMDIN_GROUP_OFFLINE_MSG_SAVE)
                        {
                                group_id_ = 0;
                                user_id_ = 0;
                                cmd_len_ = 0;
                        }
                        DWORD getSize() {
                                return sizeof(*this) + cmd_len_*cmd_data_[0];
                        }
                        DWORD group_id_;
                        DWORD user_id_;
                        WORD cmd_len_;
                        BYTE cmd_data_[0];
                };

                struct stIndividualHistoryMsgSave:
                        t_NullCmd
                {
                        stIndividualHistoryMsgSave():
                                t_NullCmd(CMDIN_SESSION, SCMDIN_INDIVIDUAL_HISTORY_MSG_SAVE)
                        {
                                sender_id_ = 0;
                                receiver_id_ = 0;
                                msg_id_ = 0;
                                msg_type_ = eChatMsgType_text;
                                size_ = 0;
                        }

                        uint32_t getSize() const
                        {
                                return sizeof(*this) + size_ * sizeof(data_[0]);
                        }

                        uint32_t sender_id_;
                        uint32_t receiver_id_;
                        uint32_t msg_id_;
                        uint8_t msg_type_;
                        uint16_t size_;
                        char data_[0];
                };

                struct stRoomHistoryMsgSave:
                        t_NullCmd
                {
                        stRoomHistoryMsgSave():
                                t_NullCmd(CMDIN_ROOM, SCMDIN_ROOM_HISTORY_MSG_SAVE)
                        {
                                room_id_ = 0;
                                user_id_ = 0;
                                msg_type_ = eChatMsgType_text;
                                size_ = 0;
                        }

                        uint32_t getSize() const
                        {
                                return sizeof(*this) + size_ * sizeof(data_[0]);
                        }

                        uint32_t room_id_;
                        uint32_t user_id_;
                        uint8_t msg_type_;
                        uint16_t size_;
                        char data_[0];
                };
        }; //namespace Record
}; //namespace Cmd
#pragma pack() //pack(1)

#endif //HISTORYMSG_COMMAND_IN_H_
